package com.sanyang.pda.presenter;


import com.sanyang.pda.bean.ManualOutBoundStatisticsBean;
import com.sanyang.pda.contract.HomeContract;
import com.sanyang.pda.contract.ManualOutBoundStatisticsContract;
import com.sanyang.pda.net.NetUtils;
import com.wangshen.base.net.bean.BaseRowsAppEntity;
import com.wangshen.base.ui.mvp.base.presenter.BasePresenter;
import com.wangshen.base.ui.mvp.base.refresh.BaseRecyclerListPresenter;
import com.wangshen.base.ui.mvp.base.refresh.BaseRecyclerRefreshPresenter;
import com.wangshen.base.ui.mvp.base.refresh.RequestCallback;

import java.util.List;

import io.reactivex.functions.Consumer;

public class ManualOutBoundStatisticsPresenter extends BaseRecyclerRefreshPresenter<ManualOutBoundStatisticsContract.View, ManualOutBoundStatisticsBean> implements ManualOutBoundStatisticsContract.Presenter {
    private String deliveryNo;

    public ManualOutBoundStatisticsPresenter(String deliveryNo) {
        this.deliveryNo = deliveryNo;
    }

    @Override
    public void onRefresh(RequestCallback<ManualOutBoundStatisticsBean> callback) {
        deliveryStatistics(getCurrentPage(),callback);
    }

    @Override
    public void onLoadMore(RequestCallback<ManualOutBoundStatisticsBean> callback) {
        deliveryStatistics(getCurrentPage(),callback);
    }

    @Override
    public void deliveryStatistics(int num,RequestCallback<ManualOutBoundStatisticsBean> callback) {
        NetUtils.geApi().deliveryStatistics(getCurrentPage(),10,deliveryNo)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseRowsAppEntity<List<ManualOutBoundStatisticsBean>>>() {
                    @Override
                    public void accept(BaseRowsAppEntity<List<ManualOutBoundStatisticsBean>> manualOutBoundStatisticsBeanBaseRowsAppEntity) throws Exception {
                        callback.onSuccess(manualOutBoundStatisticsBeanBaseRowsAppEntity.getRows());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        callback.onFail(throwable.getMessage());
                    }
                });

    }
}
